/*
*********************************************************************************
Description:	Produces main regression results, using could have control sample

Uses:			"$mergedata\Couldhavesample.dta"	

Saves:			-	

*********************************************************************************
*/


*****************************************************
*FIGURES 2 and 3: Differenced LATE regression (2SLS)*
*****************************************************

capture program drop couldHaveResults
program define couldHaveResults

	preserve

	syntax [using/] 
	if ("`using'" != "") use "`using'", clear
	
	* Open file to write to
	cap file close resultsfh 
	file open resultsfh using "${results}\Fig2and3.csv", write text replace

	local firsttime = 1
	
	* Run for different outcomes
	foreach outcome of global it_cl4_cgt_cpi taxableinccg_cpi {
			
		di as text "LATE: outcome=`outcome'_diff4, ctrlvarstxt=survives, trimlevel=1"
									
		local header ""
		if (`firsttime') local header "header"
		directctrl2sls, outcome(`outcome') ctrlvars(survives) trimlevel(1) fh(resultsfh) `header' printtoscreen
		local firsttime = 0

	}
	
	file close resultsfh

	restore

end



***********************************************
*FIGURES 4: Relative dynamics by income source*
***********************************************

capture program drop couldHaveResults_byIncSource
program define couldHaveResults_byIncSource

	preserve

	syntax [using/] 
	if ("`using'" != "") use "`using'", clear
	
	*generate figure results 
	************************
	cap file close resultsfh 
		
	file open resultsfh using "${results}\Figure4.csv", write text replace 
	foreach incvar of varlist empinc_cpi sempinc_cpi propinc_cpi pensinc_cpi divinc_cpi {
		directctrlreg, outcome(`incvar') ctrlvars(survives) trimlevel(1) fh(resultsfh) header printtoscreen
	}
	file close resultsfh 

	*NOTE: for each income source, need to divide the results by the value in the peak year for that source to get normalised values for figure

end

exit

